package demo;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-06-01
 * Time: 10:19
 */
public class Test {
    public static void main(String[] args) {
        //两个对象的比较
        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();
        Student student1 = new Student("zhangsan", 20);
        Student student2 = new Student("lisi", 30);
        System.out.println("根据年龄比：" + ageComparator.compare(student1, student2));
        System.out.println("根据姓名比：" + nameComparator.compare(student1, student2));

        //一组对象的比较
        Student[] students = new Student[]{
                new Student("zhangsan", 10),
                new Student("lisi", 18),
                new Student("wangwu", 9)};
        System.out.println("排序前：" + Arrays.toString(students));
        Arrays.sort(students, ageComparator);
        System.out.println("根据年龄排序后：" + Arrays.toString(students));
        Arrays.sort(students, nameComparator);
        System.out.println("根据姓名排序后：" + Arrays.toString(students));
    }
}
